function showDiv(object) { var object = document.getElementById(object);	if(!object) return;	object.style.display='block';	 object.style.visibility='visible';	}	
function hideDiv(objname) {	var object = document.getElementById(objname);	 if(!object) return;	object.style.visibility='hidden';	object.style.display='none';	}
function hideAll() { hideDiv("ConcordMap");hideDiv("SantaMonicaMap");hideDiv("MillValleyMap"); }
function showCommunityMap (community) { if (community=="millvalley") showDiv("MillValleyMap"); else if (community=="santamonica") showDiv("SantaMonicaMap"); else showDiv("ConcordMap");  }

function hideSlices () {
	hideDiv("pie-slice-1"); hideDiv("pie-slice-2"); hideDiv("pie-slice-3"); hideDiv("pie-slice-4"); hideDiv("pie-slice-5"); 
hideDiv("concord-pie-slice-1"); hideDiv("concord-pie-slice-2"); hideDiv("concord-pie-slice-3"); hideDiv("concord-pie-slice-4"); hideDiv("concord-pie-slice-5"); 
hideDiv("marin-pie-slice-1"); hideDiv("marin-pie-slice-2"); hideDiv("marin-pie-slice-3"); hideDiv("marin-pie-slice-4"); hideDiv("marin-pie-slice-5"); 
}

function replaceCommunity () {
	var where = document.getElementById("where");
	if (where && document.community) 	where.innerHTML = getDisplayTextCommunity(document.community);
	else where.innerHTML = "Concord" ;
	}
function switchCommunities () {
	hideAll(); showCommunityMap(document.community); replaceCommunity();
	}

	
	
// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
//                 var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
//               if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
//              document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
	div2use= document.getElementById("portal-header");
	//div2use.innerHTML = "" + nw;
	//div2use.style.backgroundPosition="" + tempX + "%";	

  return true
}

function jump(category, community , approved) {
  strHREF = "/directory/theResults2?community=" + community; //use new Results function for category-independent
  if (category && category != "") strHREF = "theResults?community=" + community + "&metacategory=" + category ;
  if ( approved == 1) strHREF += '&approved=1'  ;
  window.location = strHREF;

}

function setCommunity(newCommunity) {
  setCookie('community', newCommunity);
  var community = newCommunity;
  document.community = newCommunity;
  //alert("setting community = " + newCommunity);
}

function getCommunity() {
	var comm= getCookie('community');
	//alert("getting community = " + comm);
	if (!comm || comm =='' || comm=="null") comm="concord";
	document.community = comm;
	return comm;
	}


/*
UTILITY JAVASCRIPTS FOR HTTP, AJAX REQUESTS/RESPONSES, COOKIES, BROWSER CHECK, ETC. ... 

Author: Bryan Wilson (code by other authors factored to this new file)
Original Creation Date: 2006.08.03

*/

/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

function setCookie(name, value, expires, path, domain, secure) {
  var path = "/";
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;  
  //alert("setting cookie " + name + " " + value);
}

/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
    //alert("getting cookie " + name + " " + unescape(dc.substring(begin + prefix.length, end)));
  return unescape(dc.substring(begin + prefix.length, end));
}

/* TODO: Make the following function more dynamic or at least get from a JS file
   via Plone portal_javascripts, rather than embedded in DTML.
 */
function getDisplayTextCommunity(community) {

  if(community == 'concord') {
    return "Concord";
  } else if(community == 'millvalley') {
    return "Marin County";
  } else if(community == 'santamonica') {
    return "Santa Monica";
  }
  return "not selected";
}

function setHomePageCommunity(community) {
  document.community = community;
  setCookie('community',community);
  switchCommunities();
}


var kount = 0
function set_background_pan() {
	var now = new Date();
	nw = now.getTime(); //milliseconds since 1970
kount += 1;
	div2use= document.getElementById("portal-header");
	//div2use.innerHTML = "" + nw;

	div2use.style.backgroundPosition="" + kount/3 + "% 0%";	
        div2use= document.getElementById("panner");

	}

function hide_unnecessary (){
	if (location.href.indexOf("portal_factory/RichDocument") > 0) {
	 hideDiv("archetypes-fieldname-relatedItems");
	 hideDiv("attachment-controls");
	 hideDiv("archetypes-fieldname-allowDiscussion");
	 hideDiv("archetypes-fieldname-id");
	}
	if (location.href.indexOf("login_form?came_from") > 0 && location.href.indexOf("RichDocument") > 0) {
	 alert('To submit a profile, first log in with the name "guest" and password "goodstuff"');
	}

}

function foobly () {
	var theParagraph = document.getElementById('region-content');
	if( !theParagraph.childNodes[1].firstChild ) {
		window.alert('Your browser has an incorrect implementation of firstChild');
	} else {
		window.alert( 'The value of the text node is:\n' +
			theParagraph.childNodes[1].firstChild.nodeValue );
	}
	}
//var panning =setInterval(set_background_pan, 50);

function set_tab_selected (tabname, urlstring) {
	var tab = document.getElementById(tabname);
	var url = location.href;
	if (url.indexOf(urlstring) >=0 || !urlstring) tab.setAttribute("class", "selected");
}

var evenodd="true"; //for zebra-tables

function hideSidebar () {
	hideDiv("left-column");
	document.write("<style><!-- td.left-column {display: none; visibility: hidden}");
	document.write("#sub-banner { padding-bottom: 0px; padding-top: 0px;margin-bottom: 0px; margin-top : 0px;} --></style>");
}

function pop_one_up (tagtext, link, width, height, windowname) {
	if (!windowname) windowname = "popup";
	if (!width) width= "500";
	if (!height) height = "500";
	document.write ('<a href="#"  onclick="' + windowname + '=window.open(\'' + link + '\',\'' + windowname + '\',\'toolbar=yes,location=no,directories=no,status=yes,menubar=no,titlebar=no,scrollbars=yes,resizable=yes,width=' + width + ',height=' + height + '\'); ' + windowname + '.focus(); return false;">')
	document.write (tagtext);
	document.write ('</a>');
}